ds_map_add_map


描述

With this function you can assign a (previously created) ds_map to a key within the given ds_map. This function is designed for creating JSON compatible maps which you would then encode using json_encode and should only be used in conjunction with that functionality. If a ds_map has another map added in this way, then destroying the parent map will also destroy the contained maps and free their memory.


语法:

ds_map_add_map(id, key, value)

参数 描述
id The id of the map to use.
key The key for the added map.
The id of the map to add.


返回:

N/A(无返回值)


例如:

var j_map = ds_map_create();
var j_list = ds_list_create();
var sub_map = ds_map_create();
ds_map_add_list(sub_map, "list", j_list);
ds_map_add(sub_map, "array", j_array);
ds_map_add_map(j_map, "map", sub_map);
var j = json_encode(j_map);
ds_map_destroy(j_map);

The above code will create two ds_maps, and then populate one with a list and an array before adding it into the second, which is then encoded into a JSON string. The map is then destroyed to remove it, and any other maps or lists that it contains, from memory.